<template>

<div>
    自定义组件2
    <button @click="sendid">传递id给父组件</button>
    <br>
    <button @click="sendmsg">mitt插件传递数据</button>
</div>
</template>

<script setup>
import {ref} from "vue"
import {onMounted} from "vue"
import bus from "@/utils/bus.js"

import {defineEmits} from "vue"
const emit = defineEmits(['sendId'],['sendMoney'],)  //事件发射器

function sendid(){
    // 发送事件
    emit('sendId',id.value)
}

// 子传父要求：把id传给父组件
let id = ref(10001)
let money= ref(9999)
let msg = ref('哈哈哈哈')

onMounted(()=>{
    emit('sendMoney',money.value)
})
function sendmsg(){
    // 发布数据
    bus.emit('msg',msg)

}



</script>